home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / c / cwebbin_p13.lha / cwebbin-p13 / wmerge.cxx < prev   
C/C++ Source or Header  |  1995-09-19  |  19KB  |  942 lines

  1. #define buf_size 1024 \
  2.  
  3. #define max_include_depth 10 \
  4.  
  5. #define max_file_name_length 255
  6. #define cur_file file[include_depth]
  7. #define cur_file_name file_name[include_depth]
  8. #define cur_line line[include_depth]
  9. #define web_file file[0]
  10. #define web_file_name file_name[0] \
  11.  
  12. #define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
  13. strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) )  \
  14.  
  15. #define too_long() {include_depth--; \
  16. err_print("! Include file name too long") ;goto restart;} \
  17.  
  18. #define spotless 0
  19. #define harmless_message 1
  20. #define error_message 2
  21. #define fatal_message 3
  22. #define mark_harmless {if(history==spotless) history= harmless_message;}
  23. #define mark_error history= error_message \
  24.  
  25. #define fatal(s,t) { \
  26. fprintf(stderr,s) ;err_print(t) ; \
  27. history= fatal_message;exit(wrap_up() ) ; \
  28. } \
  29.  
  30. #define RETURN_OK 0
  31. #define RETURN_WARN 5
  32. #define RETURN_ERROR 10
  33. #define RETURN_FAIL 20 \
  34.  
  35. #define show_banner flags['b']
  36. #define show_happiness flags['h'] \
  37.  
  38. #define update_terminal fflush(stderr)  \
  39.  
  40. #define max_path_length (BUFSIZ-2)  \
  41.  
  42. #define alloc_object(object,size,type)  \
  43. if(!(object= (type*) malloc((size) *sizeof(type) ) ) )  \
  44. fatal("","! Memory allocation failure") ;
  45. #define free_object(object)  \
  46. if(object) { \
  47. free(object) ; \
  48. object= NULL; \
  49. } \
  50.  
  51. /*1:*/
  52. #line 13 "examples/wmerge.w"
  53.  
  54. #line 4 "wmerg-p13.ch"
  55. #include <string.h>
  56. #include <signal.h>
  57. #include <stdio.h>
  58.  
  59. #ifdef SEPARATORS
  60. char separators[]= SEPARATORS;
  61. #else
  62. char separators[]= "://";
  63. #endif
  64.  
  65. #define PATH_SEPARATOR   separators[0]
  66. #define DIR_SEPARATOR    separators[1]
  67. #define DEVICE_SEPARATOR separators[2]
  68. #line 15 "examples/wmerge.w"
  69. #include <stdlib.h> 
  70. #include <ctype.h> 
  71. /*2:*/
  72. #line 35 "examples/wmerge.w"
  73.  
  74. typedef short boolean;
  75. typedef unsigned char eight_bits;
  76. typedef char ASCII;
  77.  
  78. #line 56 "wmerg-p13.ch"
  79. /*:2*//*5:*/
  80. #line 68 "examples/wmerge.w"
  81.  
  82. #line 66 "wmerg-p13.ch"
  83. ASCII*buffer;
  84. ASCII*buffer_end;
  85. #line 71 "examples/wmerge.w"
  86. ASCII*limit;
  87. ASCII*loc;
  88.  
  89. /*:5*//*7:*/
  90. #line 134 "examples/wmerge.w"
  91.  
  92. int include_depth;
  93. #line 93 "wmerg-p13.ch"
  94. FILE**file;
  95. FILE*change_file;
  96. char**file_name;
  97. char*change_file_name;
  98. char*alt_web_file_name;
  99. int*line;
  100. #line 143 "examples/wmerge.w"
  101. int change_line;
  102. int change_depth;
  103. boolean input_has_ended;
  104. boolean changing;
  105. boolean web_file_open= 0;
  106.  
  107. /*:7*//*8:*/
  108. #line 160 "examples/wmerge.w"
  109.  
  110. #line 112 "wmerg-p13.ch"
  111. char*change_buffer;
  112. #line 162 "examples/wmerge.w"
  113. char*change_limit;
  114.  
  115. /*:8*//*23:*/
  116. #line 478 "examples/wmerge.w"
  117.  
  118. int history= spotless;
  119.  
  120. /*:23*//*30:*/
  121. #line 575 "examples/wmerge.w"
  122.  
  123. int argc;
  124. char**argv;
  125. #line 344 "wmerg-p13.ch"
  126. char*check_file_name;
  127. char*out_file_name;
  128. boolean*flags;
  129. #line 580 "examples/wmerge.w"
  130.  
  131. /*:30*//*40:*/
  132. #line 691 "examples/wmerge.w"
  133.  
  134. #line 391 "wmerg-p13.ch"
  135. FILE*check_file;
  136. FILE*out_file;
  137. #line 693 "examples/wmerge.w"
  138.  
  139. /*:40*//*43:*/
  140. #line 419 "wmerg-p13.ch"
  141.  
  142. const char Version[]= "$VER: WMerge 3.4 [p13] ("__DATE__", "__TIME__")\n";
  143.  
  144. /*:43*//*47:*/
  145. #line 480 "wmerg-p13.ch"
  146.  
  147. char*include_path;
  148. char*p,*path_prefix,*next_path_prefix;
  149.  
  150. /*:47*//*49:*/
  151. #line 517 "wmerg-p13.ch"
  152.  
  153. int i;
  154.  
  155. /*:49*/
  156. #line 17 "examples/wmerge.w"
  157.  
  158. /*4:*/
  159. #line 51 "examples/wmerge.w"
  160.  
  161.  
  162. /*:4*//*24:*/
  163. #line 490 "examples/wmerge.w"
  164.  
  165. #line 257 "wmerg-p13.ch"
  166. void err_print(char*);
  167. #line 492 "examples/wmerge.w"
  168.  
  169. /*:24*//*32:*/
  170. #line 599 "examples/wmerge.w"
  171.  
  172. #line 361 "wmerg-p13.ch"
  173. void scan_args(void);
  174. #line 601 "examples/wmerge.w"
  175.  
  176. /*:32*//*44:*/
  177. #line 425 "wmerg-p13.ch"
  178.  
  179. int get_line(void);
  180. int input_ln(FILE*);
  181. int main(int,char**);
  182. int wrap_up(void);
  183. void check_change(void);
  184. void check_complete(void);
  185. void prime_the_change_buffer(void);
  186. void put_line(void);
  187. void reset_input(void);
  188.  
  189. /*:44*//*45:*/
  190. #line 438 "wmerg-p13.ch"
  191.  
  192. static boolean set_path(char*,char*);
  193.  
  194. /*:45*//*52:*/
  195. #line 543 "wmerg-p13.ch"
  196.  
  197. void catch_break(int);
  198.  
  199. /*:52*/
  200. #line 18 "examples/wmerge.w"
  201.  
  202. /*6:*/
  203. #line 93 "examples/wmerge.w"
  204.  
  205. #line 74 "wmerg-p13.ch"
  206. int input_ln(
  207. FILE*fp)
  208. #line 96 "examples/wmerge.w"
  209. {
  210. register int c= EOF;
  211. register char*k;
  212. if(feof(fp))return(0);
  213. limit= k= buffer;
  214. while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
  215. if((*(k++)= c)!=' ')limit= k;
  216. if(k>buffer_end)
  217. if((c= getc(fp))!=EOF&&c!='\n'){
  218. ungetc(c,fp);loc= buffer;err_print("! Input line too long");
  219.  
  220. }
  221. if(c==EOF&&limit==buffer)return(0);
  222.  
  223. return(1);
  224. }
  225.  
  226. /*:6*//*9:*/
  227. #line 171 "examples/wmerge.w"
  228.  
  229. #line 119 "wmerg-p13.ch"
  230. void prime_the_change_buffer(void)
  231. #line 174 "examples/wmerge.w"
  232. {
  233. change_limit= change_buffer;
  234. /*10:*/
  235. #line 185 "examples/wmerge.w"
  236.  
  237. while(1){
  238. change_line++;
  239. if(!input_ln(change_file))return;
  240. if(limit<buffer+2)continue;
  241. if(buffer[0]!='@')continue;
  242. if(isupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  243. if(buffer[1]=='x')break;
  244. if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
  245. loc= buffer+2;
  246. err_print("! Missing @x in change file");
  247.  
  248. }
  249. }
  250.  
  251. /*:10*/
  252. #line 176 "examples/wmerge.w"
  253. ;
  254. /*11:*/
  255. #line 202 "examples/wmerge.w"
  256.  
  257. do{
  258. change_line++;
  259. if(!input_ln(change_file)){
  260. err_print("! Change file ended after @x");
  261.  
  262. return;
  263. }
  264. }while(limit==buffer);
  265.  
  266. /*:11*/
  267. #line 177 "examples/wmerge.w"
  268. ;
  269. /*12:*/
  270. #line 212 "examples/wmerge.w"
  271.  
  272. {
  273. change_limit= change_buffer-buffer+limit;
  274. #line 125 "wmerg-p13.ch"
  275. strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  276. #line 216 "examples/wmerge.w"
  277. }
  278.  
  279. /*:12*/
  280. #line 178 "examples/wmerge.w"
  281. ;
  282. }
  283.  
  284. /*:9*//*13:*/
  285. #line 230 "examples/wmerge.w"
  286.  
  287. #line 132 "wmerg-p13.ch"
  288. void check_change(void)
  289. #line 233 "examples/wmerge.w"
  290. {
  291. int n= 0;
  292. if(lines_dont_match)return;
  293. while(1){
  294. changing= 1;change_line++;
  295. if(!input_ln(change_file)){
  296. err_print("! Change file ended before @y");
  297.  
  298. change_limit= change_buffer;changing= 0;
  299. return;
  300. }
  301. if(limit>buffer+1&&buffer[0]=='@'){
  302. if(isupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  303. /*14:*/
  304. #line 263 "examples/wmerge.w"
  305.  
  306. if(buffer[1]=='x'||buffer[1]=='z'){
  307. loc= buffer+2;err_print("! Where is the matching @y?");
  308.  
  309. }
  310. else if(buffer[1]=='y'){
  311. if(n>0){
  312. loc= buffer+2;
  313. fprintf(stderr,"\n! Hmm... %d ",n);
  314. err_print("of the preceding lines failed to match");
  315.  
  316. }
  317. change_depth= include_depth;
  318. return;
  319. }
  320.  
  321. /*:14*/
  322. #line 247 "examples/wmerge.w"
  323. ;
  324. }
  325. /*12:*/
  326. #line 212 "examples/wmerge.w"
  327.  
  328. {
  329. change_limit= change_buffer-buffer+limit;
  330. #line 125 "wmerg-p13.ch"
  331. strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  332. #line 216 "examples/wmerge.w"
  333. }
  334.  
  335. /*:12*/
  336. #line 249 "examples/wmerge.w"
  337. ;
  338. changing= 0;cur_line++;
  339. while(!input_ln(cur_file)){
  340. if(include_depth==0){
  341. err_print("! CWEB file ended during a change");
  342.  
  343. input_has_ended= 1;return;
  344. }
  345. include_depth--;cur_line++;
  346. }
  347. if(lines_dont_match)n++;
  348. }
  349. }
  350.  
  351. /*:13*//*15:*/
  352. #line 282 "examples/wmerge.w"
  353.  
  354. #line 139 "wmerg-p13.ch"
  355. void reset_input(void)
  356. #line 285 "examples/wmerge.w"
  357. {
  358. limit= buffer;loc= buffer+1;buffer[0]= ' ';
  359. #line 146 "wmerg-p13.ch"
  360. include_depth= 0;cur_line= 0;change_line= 0;
  361. /*16:*/
  362. #line 297 "examples/wmerge.w"
  363.  
  364. if((web_file= fopen(web_file_name,"r"))==NULL){
  365. strcpy(web_file_name,alt_web_file_name);
  366. if((web_file= fopen(web_file_name,"r"))==NULL)
  367. fatal("! Cannot open input file ",web_file_name);
  368. }
  369.  
  370.  
  371. web_file_open= 1;
  372. if((change_file= fopen(change_file_name,"r"))==NULL)
  373. fatal("! Cannot open change file ",change_file_name);
  374.  
  375. /*:16*/
  376. #line 147 "wmerg-p13.ch"
  377. ;
  378. #line 289 "examples/wmerge.w"
  379. change_depth= include_depth;
  380. changing= 1;prime_the_change_buffer();changing= !changing;
  381. limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;
  382. }
  383.  
  384. /*:15*//*17:*/
  385. #line 315 "examples/wmerge.w"
  386.  
  387. get_line()
  388. {
  389. restart:
  390. if(changing&&include_depth==change_depth)
  391. /*21:*/
  392. #line 423 "examples/wmerge.w"
  393. {
  394. change_line++;
  395. if(!input_ln(change_file)){
  396. err_print("! Change file ended without @z");
  397.  
  398. buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
  399. }
  400. if(limit>buffer){
  401. *limit= ' ';
  402. if(buffer[0]=='@'){
  403. if(isupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  404. if(buffer[1]=='x'||buffer[1]=='y'){
  405. loc= buffer+2;
  406. err_print("! Where is the matching @z?");
  407.  
  408. }
  409. else if(buffer[1]=='z'){
  410. prime_the_change_buffer();changing= !changing;
  411. }
  412. }
  413. }
  414. }
  415.  
  416. /*:21*/
  417. #line 320 "examples/wmerge.w"
  418. ;
  419. if(!changing||include_depth>change_depth){
  420. /*20:*/
  421. #line 407 "examples/wmerge.w"
  422. {
  423. cur_line++;
  424. while(!input_ln(cur_file)){
  425. if(include_depth==0){input_has_ended= 1;break;}
  426. else{
  427. fclose(cur_file);include_depth--;
  428. if(changing&&include_depth==change_depth)break;
  429. cur_line++;
  430. }
  431. }
  432. if(!changing&&!input_has_ended)
  433. if(limit-buffer==change_limit-change_buffer)
  434. if(buffer[0]==change_buffer[0])
  435. if(change_limit>change_buffer)check_change();
  436. }
  437.  
  438. /*:20*/
  439. #line 322 "examples/wmerge.w"
  440. ;
  441. if(changing&&include_depth==change_depth)goto restart;
  442. }
  443. loc= buffer;*limit= ' ';
  444. if(*buffer=='@'&&(*(buffer+1)=='i'||*(buffer+1)=='I')){
  445. loc= buffer+2;
  446. while(loc<=limit&&(*loc==' '||*loc=='\t'||*loc=='"'))loc++;
  447. if(loc>=limit){
  448. err_print("! Include file name not given");
  449.  
  450. goto restart;
  451. }
  452. if(include_depth>=max_include_depth-1){
  453. err_print("! Too many nested includes");
  454.  
  455. goto restart;
  456. }
  457. include_depth++;
  458. /*19:*/
  459. #line 366 "examples/wmerge.w"
  460. {
  461. #line 182 "wmerg-p13.ch"
  462. static char*temp_file_name;
  463. #line 368 "examples/wmerge.w"
  464. char*cur_file_name_end= cur_file_name+max_file_name_length-1;
  465. char*k= cur_file_name,*kk;
  466. int l;
  467.  
  468. #line 188 "wmerg-p13.ch"
  469. alloc_object(temp_file_name,max_file_name_length,char);
  470. while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
  471. #line 373 "examples/wmerge.w"
  472. if(k>cur_file_name_end)too_long();
  473.  
  474. *k= '\0';
  475. if((cur_file= fopen(cur_file_name,"r"))!=NULL){
  476. cur_line= 0;
  477. goto restart;
  478. }
  479. #line 218 "wmerg-p13.ch"
  480. if(0==set_path(include_path,getenv("CWEBINPUTS"))){
  481. include_depth--;goto restart;
  482. }
  483. path_prefix= include_path;
  484. while(path_prefix){
  485. for(kk= temp_file_name,p= path_prefix,l= 0;
  486. p&&*p&&*p!=PATH_SEPARATOR;
  487. *kk++= *p++,l++);
  488. if(path_prefix&&*path_prefix&&*path_prefix!=PATH_SEPARATOR&&
  489. *--p!=DEVICE_SEPARATOR&&*p!=DIR_SEPARATOR){
  490. *kk++= DIR_SEPARATOR;l++;
  491. }
  492. if(k+l+2>=cur_file_name_end)too_long();
  493. strcpy(kk,cur_file_name);
  494. if((cur_file= fopen(temp_file_name,"r"))!=NULL){
  495. cur_line= 0;goto restart;
  496. }
  497. if((next_path_prefix= strchr(path_prefix,PATH_SEPARATOR))!=NULL)
  498. path_prefix= next_path_prefix+1;
  499. else break;
  500. }
  501. #line 404 "examples/wmerge.w"
  502. include_depth--;err_print("! Cannot open include file");goto restart;
  503. }
  504.  
  505. /*:19*/
  506. #line 340 "examples/wmerge.w"
  507. ;
  508. }
  509. return(!input_has_ended);
  510. }
  511.  
  512. #line 153 "wmerg-p13.ch"
  513. void put_line(void)
  514. #line 346 "examples/wmerge.w"
  515. {
  516. char*ptr= buffer;
  517. while(ptr<limit)putc(*ptr++,out_file);
  518. putc('\n',out_file);
  519. }
  520.  
  521. #line 168 "wmerg-p13.ch"
  522. /*:17*//*22:*/
  523. #line 449 "examples/wmerge.w"
  524.  
  525. #line 245 "wmerg-p13.ch"
  526. void check_complete(void){
  527. #line 452 "examples/wmerge.w"
  528. if(change_limit!=change_buffer){
  529. #line 251 "wmerg-p13.ch"
  530. strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  531. #line 454 "examples/wmerge.w"
  532. limit= buffer+(int)(change_limit-change_buffer);
  533. changing= 1;change_depth= include_depth;loc= buffer;
  534. err_print("! Change file entry did not match");
  535.  
  536. }
  537. }
  538.  
  539. /*:22*//*25:*/
  540. #line 494 "examples/wmerge.w"
  541.  
  542. #line 265 "wmerg-p13.ch"
  543. void err_print(char*s)
  544. #line 498 "examples/wmerge.w"
  545. {
  546. char*k,*l;
  547. fprintf(stderr,*s=='!'?"\n%s":"%s",s);
  548. if(web_file_open)/*26:*/
  549. #line 514 "examples/wmerge.w"
  550.  
  551. {if(changing&&include_depth==change_depth)
  552. printf(". (l. %d of change file)\n",change_line);
  553. else if(include_depth==0)fprintf(stderr,". (l. %d)\n",cur_line);
  554. else fprintf(stderr,". (l. %d of include file %s)\n",cur_line,cur_file_name);
  555. l= (loc>=limit?limit:loc);
  556. if(l>buffer){
  557. for(k= buffer;k<l;k++)
  558. if(*k=='\t')putc(' ',stderr);
  559. else putc(*k,stderr);
  560. putchar('\n');
  561. for(k= buffer;k<l;k++)putc(' ',stderr);
  562. }
  563. for(k= l;k<limit;k++)putc(*k,stderr);
  564. putc('\n',stderr);
  565. }
  566.  
  567. /*:26*/
  568. #line 501 "examples/wmerge.w"
  569. ;
  570. update_terminal;mark_error;
  571. }
  572.  
  573. /*:25*//*28:*/
  574. #line 546 "examples/wmerge.w"
  575.  
  576. #line 297 "wmerg-p13.ch"
  577. int wrap_up(void){
  578. #line 303 "wmerg-p13.ch"
  579. if(history>spotless)putchar('\n');
  580. /*56:*/
  581. #line 601 "wmerg-p13.ch"
  582.  
  583. if(out_file)
  584. fclose(out_file);
  585. if(check_file)
  586. fclose(check_file);
  587. if(check_file_name)
  588. remove(check_file_name);
  589.  
  590. /*:56*/
  591. #line 304 "wmerg-p13.ch"
  592.  
  593. /*29:*/
  594. #line 553 "examples/wmerge.w"
  595.  
  596. switch(history){
  597. case spotless:if(show_happiness)fprintf(stderr,"(No errors were found.)\n");break;
  598. case harmless_message:
  599. fprintf(stderr,"(Did you see the warning message above?)\n");break;
  600. case error_message:
  601. fprintf(stderr,"(Pardon me, but I think I spotted something wrong.)\n");break;
  602. case fatal_message:fprintf(stderr,"(That was a fatal error, my friend.)\n");
  603. }
  604.  
  605. /*:29*/
  606. #line 305 "wmerg-p13.ch"
  607. ;
  608. #line 312 "wmerg-p13.ch"
  609. #ifdef __TURBOC__
  610. {
  611. int return_val;
  612.  
  613. switch(history){
  614. case harmless_message:return_val= RETURN_WARN;break;
  615. case error_message:return_val= RETURN_ERROR;break;
  616. case fatal_message:return_val= RETURN_FAIL;break;
  617. default:return_val= RETURN_OK;
  618. }
  619. return(return_val);
  620. }
  621. #else
  622. switch(history){
  623. case harmless_message:return(RETURN_WARN);break;
  624. case error_message:return(RETURN_ERROR);break;
  625. case fatal_message:return(RETURN_FAIL);break;
  626. default:return(RETURN_OK);
  627. }
  628. #endif
  629. #line 551 "examples/wmerge.w"
  630. }
  631.  
  632. /*:28*//*33:*/
  633. #line 603 "examples/wmerge.w"
  634.  
  635. #line 368 "wmerg-p13.ch"
  636. void scan_args(void)
  637. #line 606 "examples/wmerge.w"
  638. {
  639. char*dot_pos;
  640. register char*s;
  641. boolean found_web= 0,found_change= 0,found_out= 0;
  642.  
  643. boolean flag_change;
  644.  
  645. while(--argc>0){
  646. if(**(++argv)=='-'||**argv=='+')/*37:*/
  647. #line 673 "examples/wmerge.w"
  648.  
  649. {
  650. if(**argv=='-')flag_change= 0;
  651. else flag_change= 1;
  652. for(dot_pos= *argv+1;*dot_pos>'\0';dot_pos++)
  653. flags[*dot_pos]= flag_change;
  654. }
  655.  
  656. /*:37*/
  657. #line 614 "examples/wmerge.w"
  658.  
  659. else{
  660. s= *argv;dot_pos= NULL;
  661. while(*s){
  662. if(*s=='.')dot_pos= s++;
  663. #line 374 "wmerg-p13.ch"
  664. else if(*s==DIR_SEPARATOR||*s==DEVICE_SEPARATOR||*s=='/')
  665. dot_pos= NULL,++s;
  666. #line 620 "examples/wmerge.w"
  667. else s++;
  668. }
  669. if(!found_web)/*34:*/
  670. #line 639 "examples/wmerge.w"
  671.  
  672. {
  673. if(s-*argv>max_file_name_length-5)
  674. /*39:*/
  675. #line 686 "examples/wmerge.w"
  676. fatal("! Filename too long\n",*argv);
  677.  
  678. /*:39*/
  679. #line 642 "examples/wmerge.w"
  680. ;
  681. if(dot_pos==NULL)
  682. sprintf(web_file_name,"%s.w",*argv);
  683. else{
  684. strcpy(web_file_name,*argv);
  685. *dot_pos= 0;
  686. }
  687. sprintf(alt_web_file_name,"%s.web",*argv);
  688. *out_file_name= '\0';
  689. found_web= 1;
  690. }
  691.  
  692. /*:34*/
  693. #line 622 "examples/wmerge.w"
  694.  
  695. else if(!found_change)/*35:*/
  696. #line 654 "examples/wmerge.w"
  697.  
  698. {
  699. if(s-*argv>max_file_name_length-4)
  700. /*39:*/
  701. #line 686 "examples/wmerge.w"
  702. fatal("! Filename too long\n",*argv);
  703.  
  704. /*:39*/
  705. #line 657 "examples/wmerge.w"
  706. ;
  707. if(dot_pos==NULL)
  708. sprintf(change_file_name,"%s.ch",*argv);
  709. else strcpy(change_file_name,*argv);
  710. found_change= 1;
  711. }
  712.  
  713. /*:35*/
  714. #line 623 "examples/wmerge.w"
  715.  
  716. else if(!found_out)/*36:*/
  717. #line 664 "examples/wmerge.w"
  718.  
  719. {
  720. if(s-*argv>max_file_name_length-5)
  721. /*39:*/
  722. #line 686 "examples/wmerge.w"
  723. fatal("! Filename too long\n",*argv);
  724.  
  725. /*:39*/
  726. #line 667 "examples/wmerge.w"
  727. ;
  728. if(dot_pos==NULL)sprintf(out_file_name,"%s.out",*argv);
  729. else strcpy(out_file_name,*argv);
  730. found_out= 1;
  731. }
  732.  
  733. /*:36*/
  734. #line 624 "examples/wmerge.w"
  735.  
  736. else/*38:*/
  737. #line 681 "examples/wmerge.w"
  738.  
  739. {
  740. fatal("! Usage: wmerge webfile[.w] [changefile[.ch] [outfile[.out]]]\n","")
  741. }
  742.  
  743. /*:38*/
  744. #line 625 "examples/wmerge.w"
  745. ;
  746. }
  747. }
  748. if(!found_web)/*38:*/
  749. #line 681 "examples/wmerge.w"
  750.  
  751. {
  752. fatal("! Usage: wmerge webfile[.w] [changefile[.ch] [outfile[.out]]]\n","")
  753. }
  754.  
  755. /*:38*/
  756. #line 628 "examples/wmerge.w"
  757. ;
  758. #line 381 "wmerg-p13.ch"
  759. #ifdef _DEV_NULL
  760. if(!found_change)strcpy(change_file_name,_DEV_NULL);
  761. #else
  762. if(!found_change)strcpy(change_file_name,"/dev/null");
  763. #endif
  764. #line 630 "examples/wmerge.w"
  765. }
  766.  
  767. /*:33*/
  768. #line 19 "examples/wmerge.w"
  769.  
  770. #line 23 "wmerg-p13.ch"
  771. int main(int ac,char**av)
  772. #line 22 "examples/wmerge.w"
  773. {
  774. argc= ac;argv= av;
  775. #line 29 "wmerg-p13.ch"
  776. /*50:*/
  777. #line 528 "wmerg-p13.ch"
  778.  
  779. if(signal(SIGINT,&catch_break)==SIG_ERR)
  780. exit(1);
  781.  
  782. /*:50*/
  783. #line 29 "wmerg-p13.ch"
  784.  
  785. /*48:*/
  786. #line 500 "wmerg-p13.ch"
  787.  
  788. alloc_object(buffer,buf_size,ASCII);
  789. buffer_end= buffer+buf_size-2;
  790. alloc_object(file,max_include_depth,FILE*);
  791. alloc_object(file_name,max_include_depth,char*);
  792. for(i= 0;i<max_include_depth;i++)
  793. alloc_object(file_name[i],max_file_name_length,char);
  794. alloc_object(change_file_name,max_file_name_length,char);
  795. alloc_object(alt_web_file_name,max_file_name_length,char);
  796. alloc_object(line,max_include_depth,int);
  797. alloc_object(change_buffer,buf_size,char);
  798. alloc_object(check_file_name,max_file_name_length,char);
  799. alloc_object(out_file_name,max_file_name_length,char);
  800. alloc_object(flags,256,boolean);
  801. alloc_object(include_path,max_path_length+2,char);
  802. strcpy(include_path,"");
  803.  
  804. /*:48*/
  805. #line 30 "wmerg-p13.ch"
  806. ;
  807. /*31:*/
  808. #line 583 "examples/wmerge.w"
  809.  
  810. show_banner= show_happiness= 1;
  811.  
  812. /*:31*/
  813. #line 31 "wmerg-p13.ch"
  814. ;
  815. #line 25 "examples/wmerge.w"
  816. /*41:*/
  817. #line 694 "examples/wmerge.w"
  818.  
  819. scan_args();
  820. #line 400 "wmerg-p13.ch"
  821. strcpy(check_file_name,out_file_name);
  822. if(check_file_name[0]!='\0'){
  823. char*dot_pos= strrchr(check_file_name,'.');
  824. if(dot_pos==NULL)strcat(check_file_name,".mtp");
  825. else strcpy(dot_pos,".mtp");
  826. }
  827. if(out_file_name[0]=='\0')out_file= stdout;
  828. else if((out_file= fopen(check_file_name,"w"))==NULL)
  829. fatal("! Cannot open output file ",check_file_name);
  830. #line 699 "examples/wmerge.w"
  831.  
  832.  
  833. /*:41*/
  834. #line 25 "examples/wmerge.w"
  835. ;
  836. reset_input();
  837. while(get_line())
  838. put_line();
  839. fflush(out_file);
  840. check_complete();
  841. fflush(out_file);
  842. #line 37 "wmerg-p13.ch"
  843. if(out_file!=stdout){
  844. fclose(out_file);out_file= NULL;
  845. /*53:*/
  846. #line 554 "wmerg-p13.ch"
  847.  
  848. if((out_file= fopen(out_file_name,"r"))!=NULL){
  849. char*x,*y;
  850. int x_size,y_size,comparison;
  851.  
  852. if((check_file= fopen(check_file_name,"r"))==NULL)
  853. fatal("! Cannot open output file",check_file_name);
  854.  
  855. alloc_object(x,BUFSIZ,char);
  856. alloc_object(y,BUFSIZ,char);
  857.  
  858. /*54:*/
  859. #line 582 "wmerg-p13.ch"
  860.  
  861. do{
  862. x_size= fread(x,1,BUFSIZ,out_file);
  863. y_size= fread(y,1,BUFSIZ,check_file);
  864. comparison= (x_size==y_size);
  865. if(comparison)comparison= !memcmp(x,y,x_size);
  866. }while(comparison&&!feof(out_file)&&!feof(check_file));
  867.  
  868. /*:54*/
  869. #line 565 "wmerg-p13.ch"
  870.  
  871.  
  872. fclose(out_file);out_file= NULL;
  873. fclose(check_file);check_file= NULL;
  874.  
  875. /*55:*/
  876. #line 593 "wmerg-p13.ch"
  877.  
  878. if(comparison)
  879. remove(check_file_name);
  880. else{
  881. remove(out_file_name);
  882. rename(check_file_name,out_file_name);
  883. }
  884.  
  885. /*:55*/
  886. #line 570 "wmerg-p13.ch"
  887.  
  888.  
  889. free_object(y);
  890. free_object(x);
  891. }
  892. else
  893. rename(check_file_name,out_file_name);
  894.  
  895. check_file_name= NULL;
  896.  
  897. /*:53*/
  898. #line 39 "wmerg-p13.ch"
  899.  
  900. }
  901. return wrap_up();
  902. #line 33 "examples/wmerge.w"
  903. }
  904.  
  905. /*:1*//*46:*/
  906. #line 450 "wmerg-p13.ch"
  907.  
  908. static boolean set_path(char*include_path,char*environment)
  909. {
  910. char*string;
  911.  
  912. alloc_object(string,max_path_length+2,char);
  913.  
  914. #ifdef CWEBINPUTS
  915. strcpy(include_path,CWEBINPUTS);
  916. #endif
  917.  
  918. if(environment){
  919. if(strlen(environment)+strlen(include_path)>=max_path_length){
  920. err_print("! Include path too long");
  921. free_object(string);return(0);
  922.  
  923. }
  924. else{
  925. sprintf(string,"%s%c%s",environment,PATH_SEPARATOR,include_path);
  926. strcpy(include_path,string);
  927. }
  928. }
  929. free_object(string);return(1);
  930. }
  931.  
  932. /*:46*//*51:*/
  933. #line 536 "wmerg-p13.ch"
  934.  
  935. void catch_break(int dummy)
  936. {
  937. history= fatal_message;
  938. exit(wrap_up());
  939. }
  940.  
  941. /*:51*/
  942.